// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var enterpriseId;
	var tools = require("tools");
	var p1 = 1,
	p2 = 1,
	p3 = 1,
	p4 = 1,
	p5 = 1,
	p6 = 1,
	p7 = 1,
	p8 = 1,
	p9 = 1,
	p10 = 1;
	var init = function(page) {
		enterpriseId = base.getUrlParam("enterpriseId");
		inquireEnterpriseLawsuitInfo();
		inquireEnterpriseNotice();
		inquireExecutedPerson();
		inquireCourtNotice();
		inquireMortgages();
		inquireEquityQualities();
		inquireOverDueTax();
		inquireAbnormalList();
		inquireAuction();
		inquireExecution();
		initevent();
	};
	var initevent = function() {
		//若未登录，则返回登陆页面
//		if(base.getData("sid")==null||base.getData("sid")==""||base.getData("sid")==undefined){
//			top.location.href="../login/login.html";
//		}
		
		$(".icon-home").unbind("click").click(function(){
			location.href = "../businessInfo/index1.html?enterpriseId=" + enterpriseId;
		});
		
		$(".tab-nav a").unbind("click").click(function(){
			tools.scrollto($(this), 600);
		});
		
		setTimeout(function(){
			var c = 0;
			$.each($(".tab-body .badge"), function() {
				var $this = $(this);
				if ($this.html() != null && $this.html() != "") {
					c = c*1 + $this.html()*1;
				}
			});
			$(".riskInfo").html(c);
		}, 3000);
	};
	
	//法院判决列表
	var inquireEnterpriseLawsuitInfo = function(skip) {
		base.fnAjax({
			action: "inquireEnterpriseLawsuitInfo.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $(".lawsuitTpl").html();
					var html = juicer(tpl, data);
					$("#tab-fy table").html(html);
					
					$("#tab-fy .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-fy] .badge").html(data.datas[0].data.total);
					var pageDom = $("#tab-fy .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p1, 10, function(p){
						p1 = p;
						inquireEnterpriseLawsuitInfo((p1-1)*10);
					})
				}
			}
		});
	};
	
	//法院公告信息
	var inquireEnterpriseNotice = function(skip) {
		base.fnAjax({
			action: "inquireEnterpriseNotice.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $(".enterpriseNotice").html();
					var html = juicer(tpl, data);
					$("#tab-gg table").html(html);
					
					$("#tab-gg .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-gg] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-gg .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p2, 10, function(p){
						p2 = p;
						inquireEnterpriseNotice((p2-1)*10);
					})
				}
			}
		});
	};
	
	//被执行人信息
	var inquireExecutedPerson = function(skip) {
		base.fnAjax({
			action: "inquireExecutedPerson.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-bzx script").html();
					var html = juicer(tpl, data);
					$("#tab-bzx table").html(html);
					
					$("#tab-bzx .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-bzx] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-bzx .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p3, 10, function(p){
						p3 = p;
						inquireExecutedPerson((p3-1)*10);
					})
				}
			}
		});
	};
	
	//失信人信息
	var inquireExecution = function(skip) {
		base.fnAjax({
			action: "inquireExecution.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-sxr script").html();
					var html = juicer(tpl, data);
					$("#tab-sxr table").html(html);
					
					$("#tab-sxr .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-sxr] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-sxr .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p4, 10, function(p){
						p4 = p;
						inquireExecution((p4-1)*10);
					})
				}
			}
		});
	};
	
	//司法拍卖信息
	var inquireAuction = function(skip) {
		base.fnAjax({
			action: "inquireAuction.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-sfpm script").html();
					var html = juicer(tpl, data);
					$("#tab-sfpm table").html(html);
					
					$("#tab-sfpm .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-sfpm] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-sfpm .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p5, 10, function(p){
						p5 = p;
						inquireAuction((p5-1)*10);
					})
				}
			}
		});
	};
	
	//经营异常信息
	var inquireAbnormalList = function(skip) {
		base.fnAjax({
			action: "inquireAbnormalList.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-jyyc script").html();
					var html = juicer(tpl, data);
					$("#tab-jyyc table").html(html);
					
					$("#tab-jyyc .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-jyyc] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-jyyc .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p6, 10, function(p){
						p6 = p;
						inquireAbnormalList((p6-1)*10);
					})
				}
			}
		});
	};
	
	//欠税信息
	var inquireOverDueTax = function(skip) {
		base.fnAjax({
			action: "inquireOverDueTax.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-qsxx script").html();
					var html = juicer(tpl, data);
					$("#tab-qsxx table").html(html);
					
					$("#tab-qsxx .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-qsxx] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-qsxx .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p7, 10, function(p){
						p7 = p;
						inquireOverDueTax((p7-1)*10);
					})
				}
			}
		});
	};
	
	//股权出质信息
	var inquireEquityQualities = function(skip) {
		base.fnAjax({
			action: "inquireEquityQualities.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-gqcz script").html();
					var html = juicer(tpl, data);
					$("#tab-gqcz table").html(html);
					
					$("#tab-gqcz .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-gqcz] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-gqcz .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p8, 10, function(p){
						p8 = p;
						inquireEquityQualities((p8-1)*10);
					})
				}
			}
		});
	};
	
	//动产抵押信息
	var inquireMortgages = function(skip) {
		base.fnAjax({
			action: "inquireMortgages.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-dcdy script").html();
					var html = juicer(tpl, data);
					$("#tab-dcdy table").html(html);
					
					$("#tab-dcdy .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-dcdy] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-dcdy .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p9, 10, function(p){
						p9 = p;
						inquireMortgages((p9-1)*10);
					})
				}
			}
		});
	};
	
	//开庭公告
	var inquireCourtNotice = function(skip) {
		base.fnAjax({
			action: "inquireCourtNotice.json", //接口名称
			oData: {
				enterpriseId: enterpriseId,
				skip: skip
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#tab-ktgg script").html();
					var html = juicer(tpl, data);
					$("#tab-ktgg table").html(html);
					
					$("#tab-ktgg .badge").html(data.datas[0].data.total);
					$("a[data-scroll=#tab-ktgg] .badge").html(data.datas[0].data.total);
					
					var pageDom = $("#tab-ktgg .pageDom");
					base.pageControl(pageDom, data.datas[0].data.total, p10, 10, function(p){
						p10 = p;
						inquireCourtNotice((p10-1)*10);
					})
				}
			}
		});
	};
	
	return {
		init: init
	};
});